package com.hehao.java_basic.pattern;


import org.junit.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Damon
 * @date 2022/8/25
 */
public class PatternDemo {
    /**
     * 数值小数类型
     */
    @Test
    public void numberTest() {
        String str = "9999";
        String pattern = "^10000$|^10000.0$|^10000.00$|" +
                "^([1-9])([0-9]{0,3})(\\.\\d{0,2})$|" +
                "^([1-9])([0-9]{0,3})$|" +
                "^([0-9])(\\.\\d{0,2})$";
        //String pattern = "^([1-9][0-9]{0,13})$";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(str);
        System.out.println(m.matches());
    }

    /**
     * 日期类型 yyyy-MM-dd
     */
    @Test
    public void dateTest() {
        String str = "2202-08-31";
        String pattern = "^(\\d{4}(-)\\d{2}(-)\\d{2})$";
        String pattern1 = "^(\\d{4}" +
                "(-)" +
                "(([0][1-9])|([1][0-2]))" +
                "(-)" +
                "(([0][1-9])|([1-2][0-9])|([3][0-1])))$";
        Pattern r = Pattern.compile(pattern1);
        Matcher m = r.matcher(str);
        System.out.println(m.matches());
    }
}
